package com.lc.communication.handle;


import com.lc.communication.vo.MessageProtocol;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 编码
 */
public class MyMessageEncoder extends MessageToByteEncoder<MessageProtocol> {
    private static final Logger log = LoggerFactory.getLogger(MyMessageEncoder.class);

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, MessageProtocol messageProtocol, ByteBuf byteBuf) throws Exception {
        //log.info("MyMessageEncoder encode方法被调用");
        byteBuf.writeInt(messageProtocol.getLen());
        byteBuf.writeBytes(messageProtocol.getContent());
    }
}
